package com.baking.service.impl;

import com.baking.dao.RoleMapper;
import com.baking.model.Role;
import com.baking.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * @Author:wrb
 * @Date :2020/1/5/0:15
 * @Describtion:
 **/
@Service
public class RoleServiceImpl implements IRoleService {

    @Autowired
    RoleMapper roleMapper;

    @Override
    public List<Role> getRoleList(Role role) {
        List<Role> roleList = null;
        try {
            roleList = roleMapper.getRoleList(role);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return roleList;
    }

    @Override
    public List<Role> getRole(Role role) {
        List<Role> roleList = null;
        try {
            roleList = roleMapper.getRole(role);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return roleList;
    }

    @Override
    public boolean updateById(Role role) {
        try {
            return roleMapper.updateById(role);
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean addRole(Role role) {
        try {
            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            role.setInsertDate(currentTime);
            return roleMapper.addRole(role);
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean deletRole(Role role) {
        try {
            return roleMapper.deletRole(role);
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

}
